package com.imooc.common.plan;

import com.imooc.common.plan.adapter.DefaultPlanServiceAdapter;
import com.imooc.common.plan.enums.PlanTypeCode;
import com.imooc.common.plan.handler.DefaultPlanHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

@RestController
@RequestMapping("plan")
public class PlanController {
    @Autowired
    private DefaultPlanServiceAdapter defaultPlanServiceAdapter;

    @GetMapping("/createPlanA")
    public Object createPlanA() {
        DefaultPlanHandler defaultPlanHandler = defaultPlanServiceAdapter.getDefaultPlanHandler(PlanTypeCode.PLAN_A.getCode());
        if (Objects.nonNull(defaultPlanHandler)){
            return defaultPlanHandler.planCreate();
        }
        return "无法匹配到相应计划类型";
    }

    @GetMapping("/createPlanB")
    public Object createPlanB() {
        DefaultPlanHandler defaultPlanHandler = defaultPlanServiceAdapter.getDefaultPlanHandler(PlanTypeCode.PLAN_B.getCode());
        if (Objects.nonNull(defaultPlanHandler)){
            return defaultPlanHandler.planCreate();
        }
        return "无法匹配到相应计划类型";
    }

    @GetMapping("/createPlanC")
    public Object createPlanC() {
        DefaultPlanHandler defaultPlanHandler = defaultPlanServiceAdapter.getDefaultPlanHandler(PlanTypeCode.PLAN_C.getCode());
        if (Objects.nonNull(defaultPlanHandler)){
            return defaultPlanHandler.planCreate();
        }
        return "无法匹配到相应计划类型";
    }

    @GetMapping("/createPlanD")
    public Object createPlanD() {
        DefaultPlanHandler defaultPlanHandler = defaultPlanServiceAdapter.getDefaultPlanHandler(PlanTypeCode.PLAN_D.getCode());
        if (Objects.nonNull(defaultPlanHandler)){
            return defaultPlanHandler.planCreate();
        }
        return "无法匹配到相应计划类型";
    }


}
